
//拿到传递参数
let can = window.location.search.split("=")[1];
let yonghu = sessionStorage.getItem("name")
if(can){
    $.ajax({
        url:`http://127.0.0.1:8088/xiang?id=${can}`,
        success(data){
            //信息插入
            $(`<h2>${data[0].name}</h2>
            <li>编号: <span>${data[0].id}</span></li>
            <li>价格: ￥<span>${data[0].jiage}</span></li>
            <li>版权: <span>${data[0].banquan}</span></li>
            <li>格式: <span>${data[0].geshi}</span></li>
            <li>介绍: <br><span>${data[0].jieshao}</span></li>`).appendTo($(".qing2"))
            //图片插入
            $(".qing1 .xiangimg").attr("style",`background: url(${data[0].tu}) no-repeat;background-size: 364px;`);
            $("#datu").attr("style",`background: url(${data[0].tu}) no-repeat;background-size: 500px;`)
            //按钮事件
            $("#xiang-con .qing2 .bt1").click(function(){
                if(yonghu){
                    //向后端数据库存储
                    let http = new XMLHttpRequest();
                    http.open("get",`http://127.0.0.1:8088/cun?name=${data[0].name}&id=${data[0].id}&jiage=${data[0].jiage}&yonghu=${yonghu}&shangpinimg=${data[0].tu}`);
                    http.send();
                    http.onreadystatechange = function(){
                        if(this.readyState === 4){
                            if(http.responseText === "dui"){
                                alert("成功加入购物车")
                            }else{
                                alert("您已加入购物车，请勿重复加入")
                            }
                        }
                    }
                }else{
                    location.href = "http://127.0.0.1/zkhl/qian/denglu.html"
                }
            })

        }
    })
}else{
    location.href = "http://127.0.0.1/zkhl/qian/index.html"
}
$("#xiang-con .qing2 .bt2").click(function(){
    if(yonghu){
        location.href = "http://127.0.0.1/zkhl/qian/gouwuche.html"
    }else{
        location.href = "http://127.0.0.1/zkhl/qian/denglu.html"
    }
})
$("#xiang-con .qing1 .xiangimg").click(function(){
    $("#meng").fadeToggle();
    $("#datu").slideToggle()
})
$("#datu").click(function(){
    $("#meng").fadeToggle();
    $("#datu").slideToggle()
})